<template>
  <el-form :model="formData" label-width="120px" ref="form" v-loading="loading" class="pr-4">
    <el-form-item label="工艺流程代号" prop="workingcode" :rules="[{ required: true, message: '工艺流程代号必须填写' }]">
      <el-input v-model="formData.workingcode" name="workingcode" clearable />
    </el-form-item>

    <el-form-item label="工艺流程名称" prop="processname" :rules="[{ required: true, message: '工艺流程名称必须填写' }]">
      <el-input v-model="formData.processname" name="processname" clearable />
    </el-form-item>

    <el-form-item label="描述" prop="description">
      <el-input type="textarea" v-model="formData.description" name="description" clearable />
    </el-form-item>

    <el-form-item label="工序类型" prop="processtype">
      <el-select v-model="formData.processtype" filterable placeholder="选择工序类型" size="large" clearable>
        <el-option v-for="item in optionslist" :key="item.value" :label="item.label" :value="item.value" />
      </el-select>
    </el-form-item>

    <el-form-item label="是否允许合并" prop="toallow">
      <el-select v-model="formData.toallow" size="large">
        <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
      </el-select>
    </el-form-item>

    <div class="flex justify-end">
      <el-button type="primary" @click="submitForm(form)">{{ $t('system.confirm') }}</el-button>
    </div>
  </el-form>
</template>

<script lang="ts" setup>
import { useCreate } from '/admin/composables/curd/useCreate'

import { useShow } from '/admin/composables/curd/useShow'
import { onMounted } from 'vue'
import http from '/admin/support/http'

const optionslist = ref([])
const options = ref([
  {
    label: '是',
    value: 1,
  },
  {
    label: '否',
    value: 0,
  },
])

const getOptions = () => {
  http.get('/promanagement/listtype').then(r => {
    optionslist.value = r.data.data
  })
}

getOptions()

const props = defineProps({
  primary: String | Number,
  api: String,
})

const { formData, form, loading, submitForm, close } = useCreate(props.api, props.primary)

if (props.primary) {
  useShow(props.api, props.primary, formData)
}

const emit = defineEmits(['close'])
onMounted(() => {
  close(() => emit('close'))
})
</script>
